home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9158 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: mozo.cc.purdue.edu!not-for-mail
  2. From: hrubin@b.stat.purdue.edu (Herman Rubin)
  3. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
  4. Subject: Re: GOTO controversy
  5. Date: 8 Mar 1996 10:15:08 -0500
  6. Organization: Purdue University Statistics Department
  7. Message-ID: <4hpits$1p1v@b.stat.purdue.edu>
  8. References: <rcshlds.1.000A6705@mailserv.mta.ca> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com>
  9. NNTP-Posting-Host: b.stat.purdue.edu
  10.  
  11. In article <4hlg11$dd7@news1.mnsinc.com>,
  12. Szu-Wen Huang <huang@mnsinc.com> wrote:
  13. >John Noland (sinan@cyberramp.net) wrote:
  14.  
  15. >[snip]
  16. >:  DON'T use a goto unless it's the only solution to the problem.
  17. >:  You have many alternatives to a goto in your above code. 
  18.  
  19. >Wrong.  'goto' will never be the only solution.  When the 'goto'
  20. >solution is more elegant than the other choices (which is entirely
  21. >possible), use 'goto'.
  22.  
  23. I agree that GOTO wo;; mever be the only solution.  One can simulate any
  24. GOTO language in a GOTO-less language.  And what is a switch or case
  25. statement other than a generalization of the Fortran computed GOTO?
  26. BTW, I have come up with a situation where the analog of the Fortran
  27. assigned GOTO (in some places  ASSIGN LOC TO K; in others GOTO K)
  28. would be quite useful in reducing transfers.
  29.  
  30. >:  A subroutine should have at most one label.
  31.  
  32. >Arbitrary number.  Does a subroutine with exactly *two* labels
  33. >automatically and magically become unreadable?
  34.  
  35. I would make it a block.  I have an extremely natural example
  36. of a block where there should be six entry labels.
  37.  
  38. Many, if not most, mathematical function libraries now have two entries
  39. in the sincos routine.  I would expect a Jacobian elliptic function
  40. routine to have at least six.
  41.  
  42. >:  All goto's should be above that label in the code.
  43.  
  44. >Above?  You mean all 'goto's should be forward jumps?  Why?
  45.  
  46. >:  The label should be in the same code block or at a more outer
  47. >:  nesting level than the goto itself.
  48.  
  49. >: Your code could be easily reorganized to not use a goto.
  50.  
  51. >That's the point against using 'goto's.  Realize however that a
  52. >good engineer is usually smarter than blind guidelines.  The
  53. >rules you raised have obvious drawbacks.  Personally, the rule
  54. >I impose upon myself is: "If you use a 'goto', you better have
  55. >a damn good reason for it and be prepared to explain why all
  56. >other constructs make the program uglier."
  57.  
  58. One of the most important reasons is that the code will run faster.
  59. Sometimes the main cost of the algorithm consistes in processing
  60. the transfers and conditional transfers.  Storing and loading
  61. vlaues which are only needed to indicate where to transfer, and
  62. the use of case or switch statements, with their overhead, can
  63. often be replaced by the use of simple goto instructions.
  64. -- 
  65. Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
  66. hrubin@stat.purdue.edu     Phone: (317)494-6054    FAX: (317)494-0558
  67.